﻿using QuanLyChoVayCaNhan.Forms;
using QuanLyChoVayCaNhan.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace QuanLyChoVayCaNhan.Classes
{
    public class TiepNhanHoSoTab : BaseTab
    {

        public TiepNhanHoSoTab(System.Windows.Forms.BindingSource hoSoBindingSource)
        {
            // TODO: Complete member initialization
            this.MainBindingDataSource = hoSoBindingSource;
        }

        public override TabType GetTabType()
        {
            return TabType.TiepNhanHoSoTab;
        }

        public override MenuItemType[] GetSupportedMenus()
        {
            if (UserManager.GetInstance().IsAdmin())
            {
                return new MenuItemType[] { MenuItemType.VIEW, MenuItemType.EDIT, MenuItemType.DELETE, MenuItemType.PRINT, MenuItemType.REFRESH };
            }
            if (UserManager.GetInstance().IsCBQHKH())
            {
                return new MenuItemType[] { MenuItemType.ADD, MenuItemType.VIEW, MenuItemType.PRINT, MenuItemType.REFRESH };
            }
            return new MenuItemType[] { MenuItemType.VIEW, MenuItemType.REFRESH };
        }

        public override void LoadData()
        {
            this.MainBindingDataSource.DataSource = ModelManager.GetInstance().db.HoSoes.ToList();
        }

        public override string GetTabTitle()
        {
            return "Tiếp nhận hồ sơ";
        }

        public override void OnAddClick()
        {
            if (!UserManager.GetInstance().IsCBQHKH())
            {
                MessageBox.Show("Bạn không có quyền tiếp nhận hồ sơ mới");
                return;
            }
            AddTiepNhanHoSo fAddTiepNhanHoSo = new AddTiepNhanHoSo();
            fAddTiepNhanHoSo.FormClosed += reloadData_FormClosed;
            fAddTiepNhanHoSo.ShowDialog();
        }

        private void reloadData_FormClosed(object sender, FormClosedEventArgs e)
        {
            LoadData();
        }

        public override void OnViewClick()
        {
            if (SelectedIndex == -1)
            {
                MessageBox.Show("Bạn chưa chọn hồ sơ nào");
                return;
            }
            ViewTiepNhanHoSo fViewTiepNhanHoSo = new ViewTiepNhanHoSo();
            fViewTiepNhanHoSo.FormClosed += reloadData_FormClosed;
            fViewTiepNhanHoSo.ShowDialog();
        }

        public override void OnEditClick()
        {
            
        }

        public override void OnDeleteClick()
        {
            if (!UserManager.GetInstance().IsAdmin())
            {
                MessageBox.Show("Bạn không có quyền thực hiện chức năng này");
                return;
            }
            if (WindowsManager.GetInstance().TabTiepNhanHoSo.SelectedIndex == -1)
            {
                MessageBox.Show("Bạn chưa chọn hồ sơ nào");
                return;
            }
            if (MessageBox.Show("Bạn có chắc chắn muốn xóa hồ sơ này?", "Xác nhận xóa", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                HoSo hs = ModelManager.GetInstance().db.HoSoes.ToList().ElementAt(WindowsManager.GetInstance().TabTiepNhanHoSo.SelectedIndex);
                ModelManager.GetInstance().db.HoSoes.Remove(hs);
                ModelManager.GetInstance().db.SaveChanges();
            }
        }

        public override void OnHelpClick()
        {
            throw new NotImplementedException();
        }

        public override void OnPrintClick()
        {
            
        }

        public override void OnRefreshClick()
        {
            LoadData();
        }

        public override void OnViewTDTDClick()
        {
            throw new NotImplementedException();
        }

        public override void OnViewTTTDClick()
        {
            throw new NotImplementedException();
        }

        public override void OnViewTSDBClick()
        {
            throw new NotImplementedException();
        }

        public override void OnEditTDTDClick()
        {
            throw new NotImplementedException();
        }

        public override void OnEditTTTDClick()
        {
            throw new NotImplementedException();
        }

        public override void OnAddTSDBClick()
        {
            throw new NotImplementedException();
        }

        public override void OnPrintTDTDClick()
        {
            throw new NotImplementedException();
        }

        public override void OnPrintTTTDClick()
        {
            throw new NotImplementedException();
        }

        public override void OnPrintTSDBClick()
        {
            throw new NotImplementedException();
        }

        public override void OnSearchKHClick()
        {
            throw new NotImplementedException();
        }
    }
}
